package com.example.commentserver.controller;

import com.example.commentserver.params.CommentParams;
import com.example.commentserver.params.PageCommentParams;
import com.example.commentserver.params.PageTalkParams;
import com.example.commentserver.params.TalkParams;
import com.example.commentserver.service.CommentService;
import com.example.commentserver.service.TalkService;
import com.example.commentserver.vo.CommentVO;
import com.example.userserver.enums.ReturnEnum;
import com.example.userserver.vo.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/talk-server")
@Api(tags = "私聊接口")
public class TalkController {
    @Autowired
    private TalkService talkService;

    @ApiOperation(value = "获取私聊详情")
    @PostMapping(value = "/talkDetail")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<PageInfo<CommentVO>> talkDetail(@RequestBody TalkParams talkParams) {
        return new Result(talkService.talkDetail(talkParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "获取未读消息列表")
    @PostMapping(value = "/talkList")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<PageInfo<CommentVO>> talkList(@RequestBody PageTalkParams pageTalkParams) {
        return new Result(talkService.talkList(pageTalkParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "删除私聊")
    @PostMapping(value = "/delete")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result deleteTalk(@RequestParam String id) {
        talkService.deleteTalk(id);
        return new Result(null, ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "修改私聊")
    @PutMapping(value = "/update")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result updateTalk(@RequestBody TalkParams talkParams) {
        return new Result(talkService.updateTalk(talkParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "新增私聊")
    @PostMapping(value = "/insert")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result insertTalk(@RequestBody TalkParams talkParams) {
        return talkService.insertTalk(talkParams);
    }
}
